/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

/**
 *
 * @author 阿椋世界第二可爱
 */


 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import db.linkdb;
 
public class controldb {
      private Statement state=null;
      private ResultSet res = null;
      linkdb deal=new linkdb();
      
       public  void dealcontroldb()//连接数据库，创建SQL语句对象
      {
    	  try {   		  
    		  deal.linkdatabase();
			state=(Statement) (deal.getconn()).createStatement();
		      } catch (SQLException e) {
			       System.out.println("创建SQL语句失败");
		      }
      }
      
       
     
      
      public  boolean verify(String username,String password)//用于验证登陆
      {
    	  String usertemp;
    	  String passtemp;
    	  if(username==null||password==null||"".equals(username)||"".equals(password)) return false;
    	  try {
    		state.execute("use login;");
			res=state.executeQuery("select * from user");
			while(res.next())
			{
			     usertemp=res.getString(1);
			     if(usertemp.equals(username))
			     {
			    	 passtemp=res.getString(2);
			    	 if(passtemp.equals(password)) return true;   		 
			     }
			}
		} catch (SQLException e) {
			System.out.println("verify中的SQL语句执行失败");
		}
    	  return false;
      }
      
      
      public  void close()//关闭连接
      {
    	  try {
			if(!state.isClosed())state.close();
			if(!res.isClosed())res.close();
			deal.close();
		} catch (SQLException e) {
			System.out.println("controldb关闭失败");
		}   	  
      }
}
